package com.ncmmall.domain.business.goods.attribute;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.ncmmall.domain.security.user.WebUser;
import org.hibernate.annotations.NotFound;
import org.hibernate.annotations.NotFoundAction;

import javax.persistence.*;
import java.util.List;

/**
 * @author linxs
 * @Description: 商品规格
 * @Date: 2019-07-09 17:12
 */
@Entity
@Table(name = "mall_goods_attribute")
@Access(AccessType.FIELD)
public class GoodsAttribute {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    /**
     * 所属商家
     */
    @OneToOne
    @JsonBackReference
    private WebUser merchant;

    /**
     * 规格名称
     */
    private String name;

    /**
     * 规格描述
     */
    private String note;

    /**
     * 类型
     * 1、系统
     * 2、商家
     * 3、供应商
     */
    private int type;

    /**
     * 1、启用
     * 2、禁用
     */
    private int status;

    /**
     * 一键上架使用
     */
    private long issuingSupplierAttributeId;

    @ManyToOne
    @JoinColumn(name = "parentId")
    @NotFound(action = NotFoundAction.IGNORE)
    private GoodsAttribute parent;

    @JsonBackReference
    @OneToMany(fetch = FetchType.EAGER)
    @JoinColumn(name = "parentId", nullable = true)
    private List<GoodsAttribute> attributes;

    @Transient
    private String attributeData;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getNote() {
        return note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public GoodsAttribute getParent() {
        return parent;
    }

    public void setParent(GoodsAttribute parent) {
        this.parent = parent;
    }

    public List<GoodsAttribute> getAttributes() {
        return attributes;
    }

    public void setAttributes(List<GoodsAttribute> attributes) {
        this.attributes = attributes;
    }

    public String getAttributeData() {
        return attributeData;
    }

    public void setAttributeData(String attributeData) {
        this.attributeData = attributeData;
    }

    public WebUser getMerchant() {
        return merchant;
    }

    public void setMerchant(WebUser merchant) {
        this.merchant = merchant;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public long getIssuingSupplierAttributeId() {
        return issuingSupplierAttributeId;
    }

    public void setIssuingSupplierAttributeId(long issuingSupplierAttributeId) {
        this.issuingSupplierAttributeId = issuingSupplierAttributeId;
    }
}
